package com.rh.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.rh.dto.Page;
import com.rh.entity.Department;
import com.rh.entity.Employee;
import com.rh.mapper.EmployeeMapper;
import com.rh.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;

@Service
@Transactional

public class EmployeeServiceImpl implements EmployeeService {

    @Autowired
    private EmployeeMapper employeeMapper;
    @Override
    public void addMethod(Employee employee) {
           employeeMapper.addMethod(employee);
    }

    @Override
    public void deleteMethod(Integer empId) {
    employeeMapper.deleteMethod(empId);
    }

    @Override
    public void updateMethod(Employee employee) {
        employeeMapper.updateMethod(employee);
    }

    @Override
    public Page getEmployeePage(Integer pageNo, Integer pageSize) {
        Page page=new Page();
        PageHelper.startPage(pageNo,pageSize);
        List<Employee> methodAll =employeeMapper.getMethodAll();
        PageInfo<Employee> info=new PageInfo<Employee>(methodAll);
        page.setPageNo(info.getPageNum());
        page.setPageSize(info.getPageSize());
        page.setPageCount(info.getPages());
        page.setHasPre(info.isHasPreviousPage());
        page.setHasNext(info.isHasNextPage());
        page.setCount(info.getTotal());
        page.setPage(info.getList());
        return page;
    }

    @Override
    public Employee getMethodAllById(Integer empId) {
        return employeeMapper.getMethodAllById(empId);
    }

    @Override
    public Employee getEmployeeAllByEmail(String email) {
        return employeeMapper.getEmployeeAllByEmail(email);
    }

    @Override
    public void register(String email, String empPassword,String salt) {
        employeeMapper.register(email,empPassword,salt);
    }


}
